/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newkfp;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author $alama
 */
@Entity
@Table(name = "bill")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Bill.findAll", query = "SELECT b FROM Bill b"),
    @NamedQuery(name = "Bill.check", query = "SELECT b FROM Bill b where b.billNumber = :billNumber And b.docNum = :docNum AND b.exporterID=:exporterID AND b.createDate = :createDate"),
    @NamedQuery(name = "Bill.checkExporter", query = "SELECT b FROM Bill b where b.billNumber = :billNumber And b.docNum = :docNum AND b.customerID=:customerID AND b.createDate = :createDate"),
    @NamedQuery(name = "Bill.findNotConfirmedBills", query = "SELECT b FROM Bill b WHERE b.tempFlag = 1 And b.createDate between :createDateFrom And :createDateTo"),
    @NamedQuery(name = "Bill.findNotConfirmedCusromerBill", query = "SELECT b FROM Bill b WHERE b.tempFlag = 1 AND b.exporterID = :exporterID"),
    @NamedQuery(name = "Bill.findNotConfirmedExporterBill", query = "SELECT b FROM Bill b WHERE b.tempFlag = 1 AND b.customerID = :customerID"),
    @NamedQuery(name = "Bill.findByIdBill", query = "SELECT b FROM Bill b WHERE b.idBill = :idBill"),
    @NamedQuery(name = "Bill.findByCreateDate", query = "SELECT b FROM Bill b WHERE b.createDate = :createDate"),
    @NamedQuery(name = "Bill.findByBillNumber", query = "SELECT b FROM Bill b WHERE b.billNumber = :billNumber"),
    @NamedQuery(name = "Bill.findByBillTotal", query = "SELECT b FROM Bill b WHERE b.billTotal = :billTotal"),
    @NamedQuery(name = "Bill.findByBillReminder", query = "SELECT b FROM Bill b WHERE b.billReminder = :billReminder"),
    @NamedQuery(name = "Bill.findByBillCach", query = "SELECT b FROM Bill b WHERE b.billCach = :billCach"),
    @NamedQuery(name = "Bill.findByDocNum", query = "SELECT b FROM Bill b WHERE b.docNum = :docNum"),
    @NamedQuery(name = "Bill.findByExporterID", query = "SELECT b FROM Bill b WHERE b.exporterID = :exporterID"),
    @NamedQuery(name = "Bill.findByCustomerIDAtPeriod", query = "SELECT b FROM Bill b WHERE b.customerID = :customerID And b.createDate between :createDateFrom And :createDateTo"),
    @NamedQuery(name = "Bill.findByExporterIDAtPeriod", query = "SELECT b FROM Bill b WHERE b.exporterID = :exporterID And b.createDate between :createDateFrom And :createDateTo"),
    @NamedQuery(name = "Bill.findByCustomerID", query = "SELECT b FROM Bill b WHERE b.customerID = :customerID"),
    @NamedQuery(name = "Bill.findByDisCount", query = "SELECT b FROM Bill b WHERE b.disCount = :disCount"),
    @NamedQuery(name = "Bill.checkBillNumber", query = "SELECT b FROM Bill b WHERE b.billNumber = :billNumber and b.docNum =:docNum"),
    @NamedQuery(name = "Bill.findByNonexistentFlag", query = "SELECT b FROM Bill b WHERE b.nonexistentFlag = :nonexistentFlag")})
public class Bill implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idBill")
    private Integer idBill = 1;
    @Column(name = "createDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "billNumber")
    private int billNumber;
    @Basic(optional = false)
    @NotNull
    @Column(name = "billTotal")
    private double billTotal;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "billReminder")
    private Double billReminder;
    @Column(name = "billCach")
    private Double billCach;
    @Column(name = "DocNum")
    private Integer docNum;
    @Column(name = "DisCount")
    private Double disCount;
    @Column(name = "NonexistentFlag")
    private Integer nonexistentFlag;
    @Column(name = "TempFlag")
    private Integer tempFlag;
    @JoinColumn(name = "exporterID", referencedColumnName = "idExporter")
    @ManyToOne
    private Exporter exporterID;
    @JoinColumn(name = "customerID", referencedColumnName = "idCustomer")
    @ManyToOne
    private Customer customerID;
    @OneToMany(mappedBy = "billID")
    private Collection<BillItem> billItemCollection;

    public Bill() {
    }

    public Bill(Integer idBill) {
        this.idBill = idBill;
    }

    public Bill(Integer idBill, int billNumber, double billTotal) {
        this.idBill = idBill;
        this.billNumber = billNumber;
        this.billTotal = billTotal;
    }

    public Integer getIdBill() {
        return idBill;
    }

    public void setIdBill(Integer idBill) {
        this.idBill = idBill;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public int getBillNumber() {
        return billNumber;
    }

    public void setBillNumber(int billNumber) {
        this.billNumber = billNumber;
    }

    public double getBillTotal() {
        return billTotal;
    }

    public void setBillTotal(double billTotal) {
        this.billTotal = billTotal;
    }

    public Double getBillReminder() {
        return billReminder;
    }

    public void setBillReminder(Double billReminder) {
        this.billReminder = billReminder;
    }

    public Double getBillCach() {
        return billCach;
    }

    public void setBillCach(Double billCach) {
        this.billCach = billCach;
    }

    public Integer getDocNum() {
        return docNum;
    }

    public void setDocNum(Integer docNum) {
        this.docNum = docNum;
    }

    public Double getDisCount() {
        return disCount;
    }

    public void setDisCount(Double disCount) {
        this.disCount = disCount;
    }

    public Integer getNonexistentFlag() {
        return nonexistentFlag;
    }

    public void setNonexistentFlag(Integer nonexistentFlag) {
        this.nonexistentFlag = nonexistentFlag;
    }

    public Exporter getExporterID() {
        return exporterID;
    }

    public void setExporterID(Exporter exporterID) {
        this.exporterID = exporterID;
    }

    public Customer getCustomerID() {
        return customerID;
    }

    public void setCustomerID(Customer customerID) {
        this.customerID = customerID;
    }

    @XmlTransient
    public Collection<BillItem> getBillItemCollection() {
        return billItemCollection;
    }

    public void setBillItemCollection(Collection<BillItem> billItemCollection) {
        this.billItemCollection = billItemCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idBill != null ? idBill.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Bill)) {
            return false;
        }
        Bill other = (Bill) object;
        if ((this.idBill == null && other.idBill != null) || (this.idBill != null && !this.idBill.equals(other.idBill))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "newkfp.Bill[ idBill=" + idBill + " ]";
    }

    /**
     * @return the tempFlag
     */
    public Integer getTempFlag() {
        return tempFlag;
    }

    /**
     * @param tempFlag the tempFlag to set
     */
    public void setTempFlag(Integer tempFlag) {
        this.tempFlag = tempFlag;
    }
}
